/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.minierp.dao.CodeRuleDao;
import com.minierp.helper.EncCommonHelper;
import com.minierp.model.CodeRule;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class CodeRuleFormCtr extends SimpleFormController {
	private CodeRuleDao codeRuleDao;

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String id = request.getParameter("id");
		CodeRule form = (CodeRule) this.codeRuleDao.get(CodeRule.class,
				Long.parseLong(id));
		return form;
	}

	protected void onBind(HttpServletRequest request, Object command)
			throws Exception {
	}

	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		ModelAndView mv = new ModelAndView(this.getSuccessView());
		CodeRule obj = (CodeRule) command;
		this.codeRuleDao.update(obj);
		String alertMsg = "修改成功！";
		mv.addObject("id", String.valueOf(obj.getId()));
		EncCommonHelper.setAlertMessage(request, alertMsg);
		return mv;
	}
}